<?php

class Admin_Form_BrandUpdate extends Zend_Form {

    public function init() {
        /* Form Elements & Other Definitions Here ... */
    }

    public function main($value) {        
//        $enable = "Yes";
//        if(!$value['enabled']){
//            $enable = "No";
//        }
        #form
        $this->setMethod("post")
                ->setAttrib('enctype', 'multipart/form-data');

        #name
        $name = new Zend_Form_Element_Text('name');
        $name->setLabel("Enter Brand Name:")
                ->setRequired(true)
                ->addFilter("StringTrim")
                ->setValue($value['name']);

        #menu
        $menuDb = new Admin_Model_Menu();
        $menuArray = $menuDb->fetchAllData();
        $menu = new Zend_Form_Element_Select("menu");
        $menu->setLabel("Select Appropriate Menu:")
                 ->setRequired(true)
                ->setValue($value['menu_id']);
        foreach ($menuArray as $valueMenu) {
            $menu->addMultiOption($valueMenu->id, $valueMenu->name);
        }                      

        //image upload
        $photo = new Zend_Form_Element_File('photo');
        $photo->setLabel('Choose Image:')
                ->addValidator('IsImage')
                ->addValidator('Size', false, 204800)
                ->addValidator('Extension', false, 'jpg,png,gif')
//                ->setDestination('/var/lib/openshift/5155ee6f4382ecc26a00023f/app-root/runtime/repo/php/uploads')
                ->setDestination('/var/www/zf-vijaysales/public/uploads/brands')
                ->setValueDisabled(true);

        #enabled
        $enabled = new Zend_Form_Element_Select('enabled');
        $enabled->setLabel("is Visible?")
                ->setRequired(true)
                ->setValue($value['enabled'])
                ->addMultiOptions(array('1' => 'Yes', '0' => 'No'));       

        #id
        $id = new Zend_Form_Element_Hidden('id');        
        $id->setValue($value['id']);

        #submit
        $submit = new Zend_Form_Element_Submit('submit');
        $submit->setLabel("Update Brand")
                ->setAttribs(array('class' => 'btn btn-success'));

        #
        $this->addElements(array($name,$menu,$enabled,$photo,$id,$submit));
    }

}

